/**************************************************************

Project: L-Spider
Module: Device timer routines

***************************************************************/

#include <built_in.h>

//*************************************************************

void device_timer_start( long threshold ) {
    TMR1L = Lo( threshold );
    TMR1H = Hi( threshold );
    T1CON |= 0b00000001;  // Set the TMR1ON bit
} // device_timer_start()

//========================================================

void device_timer_stop() {
    T1CON &= 0b11111110;  // Clear the TMR1ON bit
} // device_timer_stop()

//========================================================

void device_timer_reset() {
    TMR1H = 0;
    TMR1L = 0;
    PIR1 &= 0b11111110;  // Reset TMR1 overflow flag
} // device_timer_reset()

//========================================================

unsigned char device_timer_overflow() {
    return ( PIR1 & 0b00000001 );  // If bit 0 (T0IF) is set, will return 1
} // device_timer_overflow()

// *** End of file ***
